package com.lynn.salary.service.impl;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.lynn.salary.entity.SystemArgument;
import com.lynn.salary.entity.SystemFile;
import com.lynn.salary.service.ISysArgumentService;
import com.lynn.salary.util.ToolMethod;

public class SysArgumentService extends BaseService implements
		ISysArgumentService {

	public Integer totalCount() throws Exception {

		String tn = ToolMethod.getTableName(SystemArgument.class);
		String sql = "select count(*) tc from " + tn;
		List<Map<String, Object>> result = dao.executeSQL(sql);

		if (result != null && result.size() != 0) {
			Map<String, Object> map = result.get(0);
			Object o = map.get("tc");
			Integer i = Integer.parseInt(o.toString());
			return i;
		}
		return null;
	}

	public List<Map<String, Object>> findArgumentByLimit(Integer currentPage,
			Integer numPerPage) throws Exception {
		String tn = ToolMethod.getTableName(SystemArgument.class);

		String sql = "select * from " + tn + " limit " + (currentPage - 1)
				* numPerPage + "," + numPerPage;

		return dao.executeSQL(sql);
	}

	public void save(SystemArgument systemargument) throws Exception {
		this.dao.save(systemargument);
	}

	public void delete(String deleteId) throws Exception {
		this.dao.deleteById(SystemArgument.class, deleteId);
	}

	public SystemArgument findArgumentById(String editId) throws Exception {
		SystemArgument systemargument = dao.getById(SystemArgument.class,
				editId);
		return systemargument;

	}

	public void updateArgument(SystemArgument systemargument) throws Exception {
		this.dao.update(systemargument);
	}

	public SystemFile saveSf(SystemFile sf) throws Exception {
		return dao.save(sf);
	}

	public SystemFile findSfById(String id) throws Exception {

		return dao.getById(SystemFile.class, id);
	}

	public void update(SystemArgument sa) throws Exception {
		dao.update(sa);
	}

	public String getValue(String code) throws Exception {
//		t.setDao(dao);
		List<Map<String,Object>> v = getPartByCondition(SystemArgument.class, new String[]{"argValue"}, SystemArgument.getPkName()+"='"+code+"'");
		if(v == null || v.size() ==0) return null;
		
		return (String) v.get(0).get("argValue");
	}

}
